#ifndef _DATABASE_MEDIA_HELPER_H_
#define _DATABASE_MEDIA_HELPER_H_

/*----------------------------------------------------------------------
|   includes
+---------------------------------------------------------------------*/
#include "Neptune.h"
#include "PltMediaServer.h"
#include "PltMediaCache.h"

#define INVALID_NET_PORT 0
#define EXTERNAL_STREAM_SERVICE_PORT 8080

#define MEDIA_TYPE_NULL            -1
#define MEDIA_TYPE_AUDIO 		0
#define MEDIA_TYPE_PHOTOS		1
#define MEDIA_TYPE_VIDEO 		2
#define MEDIA_TYPE_DIRECTTV 	3
#define MEDIA_TYPE_PVRREC 		4
#define MEDIA_TYPE_EPG 		    5

#define MEDIA_TYPE_AUDIO_STR		"Audio"
#define MEDIA_TYPE_PHOTOS_STR 	"Photos"
#define MEDIA_TYPE_VIDEO_STR 		"Video"
#define MEDIA_TYPE_DIRECTTV_STR 	"Directtv"
#define MEDIA_TYPE_PVRREC_STR		"Pvrrec"
#define MEDIA_TYPE_EPG_STR		    "Epg"

#define MEDIA_REQUEST_FLAG_RESOURCE_SELF 	0
#define MEDIA_REQUEST_FLAG_ICON 				1
#define MEDIA_REQUEST_FLAG_SUBTITLE 			2
#define MEDIA_REQUEST_FLAG_DEVICEICON		3

#define MEDIA_REQUEST_FLAG_RESOURCE_SELF_STR	""
#define MEDIA_REQUEST_FLAG_ICON_STR				"Icon"
#define MEDIA_REQUEST_FLAG_SUBTITLE_STR			"SubTitleCaption"
#define MEDIA_REQUEST_FLAG_DEVICEICON_STR 		"deviceicon"

#define MEDIA_HASICON	0
#define MEDIA_NOICON    -1


typedef struct EpgInfo_{
	NPT_String programTitle;
	NPT_String channelID;
	NPT_String channelName;
	NPT_String scheduledStartTime;
	NPT_String scheduledEndTime;
	NPT_String description;
	bool appointPlay;
	bool appointRecord;
	
}EpgInfo;

typedef struct MediaInfo_{
	int mediatype;
	int flag;
	int hasicon;

	NPT_String parentId;
	NPT_String id;
	NPT_String filePath;
	NPT_String title;
	NPT_String objectClass;
	NPT_String mediaName;

	//NPT_String icon;
	NPT_String artist;
	int duration;
	NPT_String album;

	NPT_String addedTime;
	NPT_Array<NPT_String> subTitles;

	//epg
	EpgInfo epgInfo;
	
}MediaInfo;

typedef struct FolderInfo_{
	int subCount;
	NPT_String parentId;
	NPT_String id;
	NPT_String name;
	int subItemsType;
}FolderInfo;

typedef struct SearchArgs_{
	NPT_String object_id;
	NPT_String search_criteria;
	NPT_String filter;
	NPT_UInt32 starting_index;
	NPT_UInt32 requested_count;
	NPT_String sort_criteria;
}SearchArgs;

typedef struct BrowseArgs_{
	NPT_String object_id;
	NPT_String filter;
	NPT_UInt32 starting_index;
    NPT_UInt32 requested_count;
	NPT_String sort_criteria;
	int mediaType;//customized field
}BrowseArgs;

typedef struct BrowseOrSearchResult_{
	int totalMatches;
	NPT_List<MediaInfo> mediaList;
	NPT_Map<NPT_String,FolderInfo> folderList;
}BrowseOrSearchResult;

/***************************************************************************/
#define MEDIA_SOURCE_TYPE_FILEPATH 	"filepath"
#define MEDIA_SOURCE_TYPE_BYTEARRAY 	"bytearray"
#define MEDIA_SOURCE_TYPE_NULL 		"null"
typedef struct RequestResultMediaInfo_{

	NPT_String mediaSourceType;
	/***type 1***/
	NPT_String filePath;
	/***type 2***/
	NPT_String mimeType;
	NPT_DataBuffer dataBuffer;
}RequestResultMediaInfo;


MediaInfo getMediaRequestFromUrlPath(NPT_String urlPath);



/*****************************************************************************/

#define DMS_ROOT_ID "0"
#define DMS_AUDIO_ID  (NPT_String(DMS_ROOT_ID)+NPT_String("/")+NPT_String(MEDIA_TYPE_AUDIO_STR))//"0/Audio"
#define DMS_PHOTOS_ID (NPT_String(DMS_ROOT_ID)+NPT_String("/")+NPT_String(MEDIA_TYPE_PHOTOS_STR))//"0/Photos"
#define DMS_VIDEO_ID (NPT_String(DMS_ROOT_ID)+NPT_String("/")+NPT_String(MEDIA_TYPE_VIDEO_STR))//"0/Video"
#define DMS_DIRECTTV_ID (NPT_String(DMS_ROOT_ID)+NPT_String("/")+NPT_String(MEDIA_TYPE_DIRECTTV_STR))//"0/live-program"
#define DMS_PVRREC_ID (NPT_String(DMS_ROOT_ID)+NPT_String("/")+NPT_String(MEDIA_TYPE_PVRREC_STR))//"0/Pvrrec"
#define DMS_EPG_ID (NPT_String(DMS_ROOT_ID)+NPT_String("/")+NPT_String(MEDIA_TYPE_EPG_STR))//"0/epg"

#define DMS_DEVICE_ICON_PATH  (NPT_String("/%25/")+MEDIA_REQUEST_FLAG_DEVICEICON_STR)

typedef struct DIDLInfo_{
	int totalMachCount;
	int retNum;
	NPT_String didl;
}DIDLInfo;

DIDLInfo getFolderChildrenDIDL(const char * filter,NPT_Map<NPT_String,FolderInfo>& folders);
DIDLInfo getDirectChildrenDIDL(const char * filter,const PLT_HttpRequestContext& context,NPT_List<MediaInfo> list);
NPT_String getOneMediaItemDIDL(const char * filter,const PLT_HttpRequestContext& context,MediaInfo oneMediaInfo);
NPT_String getDeviceIconPath();

#endif








